//--------------------------------------------------------------------------------------
// Dino news
var MOD_DINO={}

MOD_DINO.dinodn="";
MOD_DINO.dinoxmlhttp=new ActiveXObject("Msxml2.XMLHTTP");//new ActiveXObject("Microsoft.XMLHTTP");
MOD_DINO.dinoparsehmtl=document.createElement('div');
MOD_DINO.ddate="";
MOD_DINO.warnings="";

MOD_DINO._din_inspect=function(opt) {
  MOD_DINO.ddate="";
  switch(MOD_DINO.dinoxmlhttp.readyState) {
  case 2: // loaded
    //alert("Loaded");
    break;
  case 3: // interactive
    //alert("Interactive");
    break;
  case 4: //complete
    if(MOD_DINO.dinoxmlhttp.status==200) {
      if(MOD_DINO.dinoxmlhttp.responseText.search("ithdraw")>=0) {	
	MOD_DINO.dinoparsehmtl.innerHTML = MOD_DINO.dinoxmlhttp.responseText;
	var nodes=MOD_DINO.dinoparsehmtl.getElementsByTagName("TR"); //[@class='epoTableText']");
	for(var n=0; n < nodes.length; n++) {
	  if(nodes[n].innerText.search("Withdrawal of application")>=0){	    
	    MOD_DINO.ddate=nodes[n].childNodes[0].innerText; 
	    break; //var alink=nodes[n].childNodes[1].childNodes[2];	    
	  }  else if(nodes[n].innerText.search("Closing of application")>=0){
	    MOD_DINO.ddate=nodes[n].childNodes[0].innerText; 
	    break;
	  }
	}  
      } else if(MOD_DINO.dinoxmlhttp.responseText.search("Closing of application")>=0){
	//alert("Application closed");
	MOD_DINO.dinoparsehmtl.innerHTML = MOD_DINO.dinoxmlhttp.responseText;
	var nodes=MOD_DINO.dinoparsehmtl.getElementsByTagName("TR"); //[@class='epoTableText']");
	for(var n=0; n < nodes.length; n++) {
	  if(nodes[n].innerText.search("Closing of application")>=0){	    
	    MOD_DINO.ddate=nodes[n].childNodes[0].innerText; 
	    //alert("Application closed the "+ddate);
	    break; //var alink=nodes[n].childNodes[1].childNodes[2];	    
	  } 
	}
      } else {
	//alert("Application alive");
      }    
      // "Decision to grant a European patent" 
      // "Claims"
      // "Final instructions (application deemed to be withdrawn/application refused)" 
      //var popup = window.open("about:","Dino");
      //popup.document.write(dinoxmlhttp.responseXML); // dinoxmlhttp.responseXML );
    } else  {
      MOD_DINO.warnings+=MOD_DINO.dinodn+" failed.\n";
    }
  }
}


MOD_DINO._reg_inspect=function(opt) {
  alert("OPT "+MOD_DINO.dinoxmlhttp.readyState);
  switch(MOD_DINO.dinoxmlhttp.readyState) {
    case 4: //complete
      alert(MOD_DINO.dinoxmlhttp.status);
      alert(MOD_DINO.dinoxmlhttp.responseText);
      if(MOD_DINO.dinoxmlhttp.status==200) {
	alert("Here we go");
	MOD_DINO.dinoparsehmtl.innerHTML = MOD_DINO.dinoxmlhttp.responseText;
	var nodes=MOD_DINO.dinoparsehmtl.getElementsByTagName("TD");
	for(var n in nodes) {
	  if(nodes[n].innerText=="No.:") {
	    alert(nodes[n+1].innerText);
	    return;
	  }
	}
      }
      alert("Boo");
  }
}
  

function dino_inspect(app) {
  MOD_DINO.dinodn=app;
  //window.open("http://dino.internal.epo.org/view/GetDossier?lang=DINO&dosnum="+app);
  MOD_DINO.dinoxmlhttp.onreadystatechange=MOD_DINO._din_inspect;
  //alert("http://dino.internal.epo.org/view/GetDossier?lang=DINO&dosnum="+app);
  MOD_DINO.dinoxmlhttp.open("POST","http://dino/view/GetDossier?lang=DINO&dosnum="+app,0,"","");
  //dinoxmlhttp.abort();
  //dinoxmlhttp.open("GET","http://q/di:"+app,0,"","");		 
  MOD_DINO.dinoxmlhttp.send(null);  
  MOD_DINO.dinoxmlhttp.abort();
}		 

function register_inspect(app) {
  MOD_DINO.dinodn=app;
  MOD_DINO.dinoxmlhttp.onreadystatechange=MOD_DINO._reg_inspect;
  //MOD_DINO.dinoxmlhttp.open("GET","http://register1.epoline.org/espacenet/regviewer?AP=07006542&CY=EP&LG=en&DB=REG",0,"","");

  //  MOD_DINO.dinoxmlhttp.open("GET","http://www.epoline.org/portal/PA_1_0_FS/DocumentViewer?RACTION=XML&RAPPNO=07006542.0",0,"","");
  //MOD_DINO.dinoxmlhttp.open("GET","http://register.epoline.org/espacenet/regviewer?AP=EP07006542",0,"","");
  //dinoxmlhttp.abort();
  //dinoxmlhttp.open("GET","http://q/di:"+app,0,"","");		 
  MOD_DINO.dinoxmlhttp.send(null);  
  MOD_DINO.dinoxmlhttp.abort();
}



function do_dinonews() {
  if(GetDossierNumber()) {
    DinoNews(GetDossierNumber());
    alert("Dino checked for news");
  }
}

function DinoNews(dn) {
  MOD_DINO.warnings="";
  if(!dn) {
    var dos_iter= new  dossier_iterator();
    var progbar = new html_progbar("Checking "+dos_iter.length()+" files",dos_iter.length());
    while(!dos_iter.end()) {
      progbar.message(dos_iter.getNumber());
      if(!dos_iter.getEndDate()) {
	dino_inspect(dos_iter.getNumber());
	if(MOD_DINO.ddate) {
	  //dos_iter.setEndDate(MOD_DINO.ddate);
	  SetActionDead(dos_iter.getNumber(),MOD_DINO.ddate);
	  //SaveDossier(dos_iter.getNumber());
	}
      }
      dos_iter.next();
      progbar.advance();
    }
    //SaveActions();
    progbar.close();
  } else {
    dino_inspect(dn);
    if(MOD_DINO.ddate) {
      //SetDossierEndDate(MOD_DINO.ddate);
      SetActionDead(dn,MOD_DINO.ddate);
      //SaveDossier(dn);
      //SaveActions();
    }
  }
  SaveActions();
  if(MOD_DINO.warnings){
    alert(MOD_DINO.warnings);
  }
}

